import logging
try:
    from .__init__ import *
except Exception as e:
    raise e

_rlog, _plog, _mlog, _tlog = get_loggers(__file__, __name__, propagate=False)

def root_logger_init(rootlogger_loglevel=logging.DEBUG,
                    console_loglevel=logging.INFO,
                    formatter=None,
                    force=True):
    rootlogger = get_logger()
    if not force:
        if rootlogger.hasHandlers():
            return rootlogger

    rootlogger.setLevel(rootlogger_loglevel)

    csh = make_color_stream_handler(loglevel=console_loglevel, formatter=formatter,
                                    logcolor_config=default_logcolor_config)

    rootlogger.addHandler(csh)

    # if os.environ['stylelogfile']:
    #     filepath = os.environ['stylelogfile']

    return rootlogger

def root_logger_deinit():
    '''remove default ColorStreamHandler'''
    rootlogger = get_logger()
    if rootlogger.hasHandlers():
        rootlogger.handlers.pop(0)
        return True
    return False

# root_logger_deinit()
# root_logger_init(rootlogger_loglevel=logging.DEBUG,
#                 console_loglevel=logging.INFO,
#                 formatter=logging.Formatter(def_fmt, datefmt=None, style='%'),
#                 force=False)

# call when import this module
_plog.setLevel(logging.WARNING)
csh = make_color_stream_handler(loglevel=logging.DEBUG,
                formatter=logging.Formatter(def_fmt, datefmt=None, style='%'),
                logcolor_config=default_logcolor_config)
_plog.addHandler(csh)
